import json

from core.result_base import ResultBase
from api.statistics import statistics
from common.logger import logger


def region_vll(params={}):
    """
    获取区域业务数量与带宽
    :return: 自定义的关键字返回结果 result
    """
    result = ResultBase()
    resp = statistics.region_vll(params=params)
    result.success = False
    try:
        resp = json.loads(resp.content.decode('utf-8'))
    except Exception as e:
        result.error = "接口返回码是500, 返回信息：{} ".format(e)
        result.msg = e
        result.response = resp
        return result
    resp = resp["result"]
    if resp['status'] == 0:
        result.success = True
    else:
        result.error = "接口返回码是 【 {} 】, 返回信息：{} ".format(resp['status'], resp["msg"])
    result.response = resp
    return result


def multi_desc_vll(params={}):
    """
    获取组网端点数量排序列表
    :return: 自定义的关键字返回结果 result
    """
    result = ResultBase()
    resp = statistics.multi_desc_vll(params=params)
    result.success = False
    try:
        resp = json.loads(resp.content.decode('utf-8'))
    except Exception as e:
        result.error = "接口返回码是500, 返回信息：{} ".format(e)
        result.msg = e
        result.response = resp
        return result
    resp = resp["result"]
    if resp['status'] == 0:
        result.success = True
    else:
        result.error = "接口返回码是 【 {} 】, 返回信息：{} ".format(resp['status'], resp["msg"])
    result.response = resp
    return result
